package java8._05_使用流;

import org.junit.Test;

import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.BiFunction;
import java.util.function.BiPredicate;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

public class _01_树脂流 {

    @Test
    public void testAndThen() {
        Stream<double[]> pythagoreanTriples2 = IntStream.rangeClosed(1, 100)
            .boxed()
            .flatMap(a ->
                IntStream.rangeClosed(a, 100)
                    .mapToObj(b -> {
                        System.out.print(a + "--" + b + "|");
                        return new double[]{a, b, Math.sqrt(a * a + b * b)};
                    })
                    .filter(t -> t[2] % 1 == 0)
            ).limit(2);

        pythagoreanTriples2.map(Arrays::toString).forEach(System.out::println);

    }

    @Test
    public void testMy() {
        Stream<String> strStream = IntStream.rangeClosed(1, 100) // 创建a
            .mapToObj(a -> IntStream.rangeClosed(a, 100)
                .mapToObj(b -> {
                    System.out.print(a + "--" + b + "|");
                    return new double[]{a, b, Math.sqrt(a * a + b * b)};
                })
                .filter(item -> item[2] % 1 == 0))
            .flatMap(item -> item)
            .limit(1)
            .map(Arrays::toString);

        strStream.forEach(System.out::println);
    }
}
